package com.foreveross.project.projectonline.model;

import java.util.Date;
import java.util.List;

import org.iff.infra.util.Assert;
import org.iff.infra.util.StringHelper;

import com.jfinal.plugin.activerecord.Model;

@SuppressWarnings("serial")
public class Project extends Model<Project> {
	public static final Project dao = new Project();
	
	public boolean save() {
		set("ID", null);
		set("CREATE_TIME", new Date());
		validate(true);
		return super.save();
	}

	public boolean update() {
		validate(false);
		return super.update();
	}
	
	public void validate(boolean isCreate) {
		if (isCreate) {
			Assert.notEmpty((String) get("NAME"), "[NAME][IS_EMPTY]");
			Assert.notEmpty((String) get("SHOW_NAME"), "[SHOW_NAME][IS_EMPTY]");
			/*if (!"N".equals(get("IS_ENABLE"))) {
				set("IS_ENABLE", "Y");
			} else {
				set("IS_ENABLE", "N");
			}*/
		}else{
			Assert.notEmpty((String) get("ID"), "[ID][IS_EMPTY]");
		}
	}
	
	public List<Project> select(){
		
		List<Project> products = Project.dao.find("select * from TD_OL_PROJECT ");
		
		return products;
	}
	
}
